import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'
// 导入全局组件注册
import Components from './components/index'
import '@/icons' // icon
// 导航守卫逻辑
import '@/permission' // permission control
import * as all from '@/directive/index'
Object.keys(all).forEach(val => {
  // val就是属性名，all[val] 就是属性值
  // console.log(val, all[val])
  Vue.directive(val, all[val])
})
// 导入全局混入对象
import indexTest from '@/mixins'
// Vue.mixin(混入对象)
Vue.mixin(indexTest)
// 导入过滤器文件内容
import * as filters from '@/filters'
// console.log(filters)
// console.log(Object.keys(filters))
Object.keys(filters).forEach(item => {
  Vue.filter(item, filters[item])
})
// const myPlugin = {
//   install() {
//     console.log('install')
//   }
// }
Vue.use(Components)

import i18n from '@/lang'
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}

// 安装elementUI插件，配置语言包
// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
Vue.use(ElementUI, { i18n: (key, value) => i18n.t(key, value) })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

// const data = [
//   { id: 2, pid: 1 },
//   { id: 3, pid: 1 },
//   { id: 1, pid: 0 },
//   { id: 4, pid: 2 },
//   { id: 5, pid: 2 },
//   { id: 6, pid: 3 }
// ]

// // 定义方法
// function tranListTreeToData(list, pid) {
//   const arr = []
//   list.forEach(item => {
//     if (item.pid === pid) {
//       const children = tranListTreeToData(list, item.id)
//       if (children.length) item.children = children
//       arr.push(item)
//     }
//   })
//   return arr
// }
// const res = tranListTreeToData(data, 0)
// console.log(res)

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
